/*
 * @FilePath: \undefinedc:\Users\sxjct\.leetcode\26.删除有序数组中的重复项.cpp
 * @Brief: 
 * @Version: 1.0
 * @Date: 2021-03-16 18:56:23
 * @Author: your name
 * @Copyright: your copyright description
 * @LastEditors: your name
 * @LastEditTime: 2021-03-16 19:07:47
 */
/*
 * @lc app=leetcode.cn id=26 lang=cpp
 *
 * [26] 删除排序数组中的重复项
 */

// @lc code=start
class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        // nums.erase(unique(nums.begin(),nums.end()), nums.end());    //unique在algorithm头文件中，功能是去重
        // return nums.size();
        if (nums.size() < 2) return nums.size();
        int j = 0;
        for (int i = 1; i < nums.size(); i++)
            if (nums[j] != nums[i]) nums[++j] = nums[i];
        return ++j;
    }
};
// @lc code=end

